package com.example.myapplication.ui.activity.web

import android.widget.LinearLayout
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.myapplication.R
import com.example.myapplication.arouter.ARouterPath
import com.just.agentweb.AgentWeb
import com.kun.base.ui.AbsBaseActivity
import kotlinx.android.synthetic.main.activity_web.*
import kotlinx.android.synthetic.main.toolbar_layout.*


/**
 *网页的activity
 *参数 ( title  标题 ；
 *  url 请求地址 )
 *
 * @author : Kun
 * @date : 2021/6/3
 * @time : 16:29
 */
@Route(path = ARouterPath.WEB)
class WebActivity : AbsBaseActivity() {
    private lateinit var mAgentWeb: AgentWeb

    /**
     * 链接地址
     */
    @JvmField
    @Autowired
    var url: String? = null

    /**
     * 标题
     */
    @JvmField
    @Autowired
    var title: String? = null

    override fun getLayoutId(): Int {
        return R.layout.activity_web
    }

    override fun initViewModel() {
    }

    override fun initView() {
        ARouter.getInstance().inject(this)
        tv_title.text = title
        iv_back.setOnClickListener { finish() }
        mAgentWeb = AgentWeb.with(this)
            .setAgentWebParent((ll_content)!!, LinearLayout.LayoutParams(-1, -1))
            .useDefaultIndicator()
            .createAgentWeb()
            .ready()
            .go(url)
    }

    override fun onBackPressed() {
        if (!mAgentWeb.back()) {
            super.onBackPressed()
        }
    }
}